package com.eml.service.service.impl;

import com.eml.service.dao.DelivererDao;
import com.eml.service.dao.impl.DeliverersDaoImpl;
import com.eml.service.entity.Deliverer;
import com.eml.service.service.DelivererService;

public class DelivererServiceImpl implements DelivererService{
    private DelivererDao delivererDao = new DeliverersDaoImpl();
    //配送员注册
    @Override
    public void delivererRegister(Deliverer deliverer) throws Exception {
        delivererDao.delivererRegister(deliverer);
    }

    //配送员登录
    @Override
    public Deliverer delivererLogin(String delivererUsername,String delivererPassword) throws Exception {
        Deliverer deliverer = delivererDao.delivererLogin(delivererUsername);
        if (deliverer == null) {
            throw new Exception("配送员用户名不存在");
        } else if (!delivererPassword.equals(deliverer.getDelivererPassword())) {
            throw new Exception("配送员密码错误");
        }
        return deliverer;
    }
//修改密码
    @Override
    public void updateDelivererPassword(String delivererUsername, String delivererPassword) throws Exception {
        int i = delivererDao.updateDelivererPassword(delivererUsername, delivererPassword);
        if (i==0){
            throw new Exception("修改失败，用户名不存在");
        }
    }
}

